package 题目集.树;

import java.util.*;

public class 左孩子右兄弟 {
    static int maxN = 100001;
    static int n;
    static final Node one=new Node(1);
    static final Node[] nodes=new Node[maxN];
    static final int[] dp=new int[maxN];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        nodes[1]=one;
        for (int i = 2; i <= n; i++) {
            int p = sc.nextInt();
            put(i, p);
        }
        int height=dfs(1);
        System.out.println(height-1);   //不算根节点
    }
    //子树的最大高度
    public static int dfs(int x){
        if (dp[x]!=0){
            return dp[x];
        }
        if (nodes[x].size()==0){
            dp[x]=1;
            return 1;
        }
        int max=0;
        for (Node node : nodes[x].child) {
            max=Math.max(max,dfs(node.id));
        }
         dp[x]= max + nodes[x].size();
        return dp[x];
    }

    public static void put(int c, int p) {
        nodes[c]=new Node(c);
        nodes[p].child.add(nodes[c]);
        nodes[c].pid=p;
    }

    static class Node {
        int pid;
        int id;
        List<Node> child=new ArrayList<>();

        public Node(int id) {
            this.id = id;
        }
        public int size(){
            return child.size();
        }
    }
}
